package com.jdbc.transaction;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class TestTransaction {
	private ApplicationContext applicationContext = null;
	private BookShopDao bookShopDao;
	private BookShopService bookShopService = null;
	{
		applicationContext = new ClassPathXmlApplicationContext("applicationContext_jdbc.xml");
		bookShopDao = applicationContext.getBean(BookShopDao.class);
		bookShopService = applicationContext.getBean(BookShopService.class);
	}
	

	@Test
	public void purchaseTest() {
		try {
			bookShopService.purchase("AA", "1001");
		} catch (BookStockException e) {
			System.out.println("TestTransaction.purchaseTest()");
		}
	}

	@Test
	public void updateUserAccountTest() {
		bookShopDao.updateUserAccount("AA", 100);
	}

	@Test
	public void updateBookStockTest() {
		bookShopDao.updateBookStock("1001");
	}

	@Test
	public void findBookPriceByIsbnTest() {
		System.out.println(bookShopDao.findBookPriceByIsbn("1001"));
	}

}
